﻿#ifndef WSWITCHNODE_H
#define WSWITCHNODE_H

#include "wbasenode.h"
#include "../common.h"
#include "../signal.hpp"

struct SwitchStateMounts
{
    SwitchStateMounts(){}
    SwitchStateMounts(tagMountPoint* sMount,tagMountPoint* eMount)
        : startMount(sMount),endMount(eMount) {}

    tagMountPoint* startMount;
    tagMountPoint* endMount;
};

class WSwitchNode : public WBaseNode
{
public:
    WSwitchNode();
    WSwitchNode(wxString pname);
    ~WSwitchNode();

    /// 建立脚本文件
    bool createScriptFile(void);
    /// 初始道岔状态
    bool initSwitchState(int state,wxString startpos,wxString endpos);
    /// 设置道岔状态
    void setSwitchState(int state);
    /// 得到道岔状态
    inline int getSwitchState(void) { return (int)m_SwitchState; }
    /// 得到道岔状态信息
    inline const SwitchStateMounts* getSwitchStateMounts(void) { return &m_SwitchStateMounts[m_SwitchState]; }
    /// 得到道岔所有挂节点信息
    inline std::map<SwitchState,SwitchStateMounts> getAllSwitchStateMounts(void) { return m_SwitchStateMounts; }

    /// 设置结点管理器
    virtual void setNodeManager(WNodeManager *pNodeManager);
    /// 工作区域改变
    virtual void changeWorkingRect(wxRect workingrect);
    /// 更新
    virtual void update(void);
    /// 绘制
    virtual void draw(maindrawscene *painter);
    /// 处理鼠标事件
    virtual bool OnMMouseEvent(wxMouseEvent event);

private:
    /// 绘制内部路线
    void drawRoute(maindrawscene *painter);

private:
    std::map<SwitchState,SwitchStateMounts> m_SwitchStateMounts;            /**< 道岔内部线路 */
    SwitchState m_SwitchState;                                              /**< 道岔状态 */
    sigslot::signal1<wxString> sig_switch_change;
    wxString m_onMouseEventString,m_onUpdateEventString,m_onDrawEventString;
};

#endif // WSWITCHNODE_H
